﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace WallCreateAndEdit.WallModule.EditWall
{
	public partial class OutWallOffsetForm : System.Windows.Forms.Form
	{
		public OutWallOffsetForm()
		{
			this.InitializeComponent();
		}

		public bool SelectOutWall
		{
			get
			{
				return this.rdbSelect.Checked;
			}
		}

		public WallRefLineType TheWallRefLineType
		{
			get
			{
				return (WallRefLineType)this.cmbWallRefLineList.SelectedIndex;
			}
		}

		private void OutWallOffsetForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SaveCompornentData();
		}

		private void OutWallOffsetForm_Load(object sender, EventArgs e)
		{
			this.LoadCompornentData();
		}

		private void LoadCompornentData()
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "OutWallOffsetForm.dat";
			if (!File.Exists(path))
			{
				base.StartPosition = FormStartPosition.CenterScreen;
				this.cmbWallRefLineList.SelectedIndex = 0;
				this.rdbAll.Checked = true;
				this.rdbSelect.Checked = false;
				return;
			}
			base.StartPosition = FormStartPosition.Manual;
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			int selectedIndex = Convert.ToInt32(streamReader.ReadLine());
			this.cmbWallRefLineList.SelectedIndex = selectedIndex;
			this.rdbAll.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.rdbSelect.Checked = Convert.ToBoolean(streamReader.ReadLine());
			try
			{
				int x = Convert.ToInt32(streamReader.ReadLine());
				int y = Convert.ToInt32(streamReader.ReadLine());
				base.Location = new Point(x, y);
			}
			catch (Exception)
			{
				streamReader.Close();
				fileStream.Close();
				return;
			}
			streamReader.Close();
			fileStream.Close();
		}

		private void SaveCompornentData()
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "OutWallOffsetForm.dat";
			FileStream fileStream = new FileStream(path, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.cmbWallRefLineList.SelectedIndex);
			streamWriter.WriteLine(this.rdbAll.Checked);
			streamWriter.WriteLine(this.rdbSelect.Checked);
			streamWriter.WriteLine(base.Location.X);
			streamWriter.WriteLine(base.Location.Y);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}
	}
}
